package com.lijin.study.java.thread.pool1;

import com.lijin.study.java.thread.task.Task;

public class ThreadTask extends Thread {

	private ThreadPool pool;
	
	private int threadNo;
	
	private boolean isWorking = false;

	public ThreadTask(ThreadPool thePool, int threadNo) {
		pool = thePool;
		this.threadNo = threadNo;
	}

	public void run() {
		while (true) {
			Task task = pool.getNext();
			try {
				isWorking = true;
				System.out.println("---Thread【" + threadNo + "】execute begin---");
				task.execute();
				System.out.println("---Thread【" + threadNo + "】execute end---");
				isWorking = false;
			} catch (Exception e) {
				System.err.println("Job exception: " + e);
			}
		}
	}
	
	public boolean isStillWorking() {
		return isWorking;
	}
}
